﻿Imports System.ServiceModel

Public Class frmGetStatusClient

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Using Client = New SrvClients.ClientesClient()
            Dim _random As New Random()
            Dim transactionID As Int64 = _random.[Next]()
            Dim token As String = String.Empty

            Dim [Error] As String
            Dim Util As New Utilerias()
            [Error] = Util.CreateToken(txtRFC.Text, transactionID, token)
            If Not String.IsNullOrEmpty([Error]) Then
                ShowUnknownError([Error])
                Return
            End If
            Try
                Dim respuesta = Client.EstatusCuenta(txtRFC.Text, token, transactionID)
                txtInvoiceAssigned.Text = respuesta.TimbresAsignados.ToString()
                txtInvoicesRemaining.Text = respuesta.TimbresDisponibles.ToString()
                '_view.InvoicesUsed=respuesta.TimbresEmitidos;
                txtDateStart.Text = respuesta.FechaInicio
                txtDateEnd.Text = respuesta.FechaFin
                txtDescription.Text = respuesta.Descripcion
            Catch validationFault As FaultException(Of SrvClients.FallaValidacion)
                Using errorForm = New frmError(TranslateFault.ToValidationError(validationFault.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch fallaServicio As FaultException(Of SrvClients.FallaServicio)
                Using errorForm = New frmError(TranslateFault.ToServiceError(fallaServicio.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch fallaSesion As FaultException(Of SrvClients.FallaSesion)
                Using errorForm = New frmError(TranslateFault.ToSessionError(fallaSesion.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch ex As Exception
                ShowUnknownError(ex.Message)
            End Try
        End Using
    End Sub
    Public Sub ShowResult(ByVal message As String)
        MessageBox.Show([String].Format("{0}", message), "Ecodex UniTest")
    End Sub
    Public Sub ShowUnknownError(ByVal message As String)
        MessageBox.Show([String].Format("Error: {0}", message), "Ecodex UniTest")
    End Sub
    Public Sub ShowSessionError(ByVal [error] As Entity.SessionError)
        MessageBox.Show([String].Format("Status {0}: {1}", [error].Status.ToString(), [error].Description), "Ecodex UniTest")
    End Sub
End Class